#!/bin/bash

test_name="rtmp_rtmp_ffmpeg"

echo -e "输入测试目标路数："
#键盘读取赋bai值du给变量num
read streamCount
#判断num的值zhi是否dao为数字，条件否则直接zhuan退出shu
expr $streamCount + 0 1>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "${streamCount} is not a number!"
exit 0
fi
#判断变量num的值是否大于0
if [ "$streamCount" -gt 0 ]
then
echo "测试目标路数：${streamCount}"
else
exit 0
fi

Current_PATH=$(cd $(dirname $0) && pwd)
ffmepgBin="${Current_PATH}/../ffmpeg-4.3.1/ffmpeg"
cd ${Current_PATH}
pwd
./stop.sh
sleep 1
killall ffmpeg
sleep 1

inputScheam="rtmp"
inputHost="192.168.1.162"
inputPort="1935"
inputUrl="${inputScheam}://${inputHost}:${inputPort}/live/test"

outputScheam="rtmp"
outputHost="192.168.1.162"
outputPort="1935"

echo "-----------------------------------------------------------"
for((i=0;i<$streamCount;i++))
do
    outputUrl="${outputScheam}://${outputHost}:${outputPort}/live/ch${i}";
    echo "${ffmepgBin} -i ${inputUrl} -c:v copy -c:a copy -f flv ${outputUrl} 1>/dev/null 2>/dev/null &"
    ${ffmepgBin} -i ${inputUrl} -c:v copy -c:a copy -f flv ${outputUrl} 1>/dev/null 2>/dev/null &
    # top -b -n 1 | head -n 5
    sleep 0.2
    echo "-----------------------------------------------------------"
done

echo "开始记录使用情况..."
for((i=0;i<100;i++))
do
    ((sec=${i}*10))
    echo "[sec：${sec}][test：${test_name}][stream：${streamCount}]-----------------------------------------------------------"
    # top -b -n 1 | head -n 5
    # echo "-----------------------------------------------------------"
    # top -b -n 1 | grep ffmpeg
    # echo "-----------------------------------------------------------"
    # top -b -n 1 | grep ffmpeg | wc
    # echo "-----------------------------------------------------------"
    # free -h
    # echo "-----------------------------------------------------------"
    uptime
    free -m
    sleep 10
    echo "-----------------------------------------------------------"
done
# ffmpeg -i "rtsp://admin:julong123@192.168.1.87:554/video1" -c copy -f flv "rtmp://127.0.0.1:1934/live/test"

# ffmpeg -i "rtsp://admin:julong123@192.168.1.87:554/video1" -c copy -f flv "rtmp://127.0.0.1:10000/live/test" >/dev/null 2>&1

# ffmpeg -i rtmp://192.168.1.152/live/level3-shelf -c:v copy -c:a copy -f flv rtmp://192.168.1.164:1934/live/ch0
